@echo off&&SETLOCAL ENABLEDELAYEDEXPANSION

@REM $P../tools/merge_bin.exe -o $P/bin/@L_all.bin $L@L.bin,0x0 $P../source/loopbus/lib/loopbus_v0.3.1_slave_alpha.bin,0xA000

set BAT_PATH=%~dp0
set PRO_PATH=%cd%
set PRO_NAME=%1
set OUT_PATH=%PRO_PATH%/bin

set version_file=%BAT_PATH%/../version.txt

set compile_ver=

:__GET_VER_STR
for /f %%a in (%version_file%) do (
    set compile_ver=%%a
    echo version: %%a
    goto __RUN_MERGE_BIN
)

:__RUN_MERGE_BIN

set OUT_BIN=%OUT_PATH%/%PRO_NAME%_%compile_ver%_all.bin

echo.
echo ----------------------------------------------------
@REM echo BAT PATH: %BAT_PATH%
@REM echo PRO PATH: %PRO_PATH%
echo PRO NAME   : %PRO_NAME%
@REM echo OUT PATH: %OUT_PATH%
echo INPUT BIN1 : %2
echo INPUT BIN2 : %3
echo OUT   BIN  : %OUT_BIN%
echo ----------------------------------------------------
echo.
echo.
echo.


if not exist "%OUT_PATH%" (
    md "%OUT_PATH%"
)

%BAT_PATH%/merge_bin.exe -o %OUT_BIN% %2 %3

:__EXIT
